// pages/02admin/00shop/shopSet.js
var app = getApp()
var appData = getApp().globalData
var _this
Page({
    data: {
        shopInfo: '',
    },

    onLoad: function (opt) {
       _this=this
      //   console.log('appData', appData)
        this.setData({
            shopInfo: appData.shopInfo,
        })
      //   console.log("【appData.shopInfo】", this.data.shopInfo)
        this.unFocus();
    },

    unFocus: function () {
        this.setData({
            seatFeeSet: 0,
            telSet: 0,
            nameSet: 0,
            wifiName: 0,
            wifiPassword: 0
        })
    },

    setTel: function () {
        if (appData.loginMode == 'boss') {
            this.setData({
                seatFeeSet: 0,
                telSet: 1,
                nameSet: 0,
                wifiName: 0,
                wifiPassword: 0
            })
        } else {
            app.toast('掌柜登录才能操作')
        }

    },

    setSeatFee: function () {
        if (appData.loginMode == 'boss') {
            this.setData({
                seatFeeSet: 1,
                telSet: 0,
                nameSet: 0,
                wifiName: 0,
                wifiPassword: 0
            })
        } else {
            app.toast('掌柜登录才能操作')
        }
    },

    setName: function () {
        if (appData.loginMode == 'boss') {
            this.setData({
                seatFeeSet: 0,
                telSet: 0,
                nameSet: 1,
                wifiName: 0,
                wifiPassword: 0
            })
        } else {
            app.toast('掌柜登录才能操作')
        }
    },
    setWifiPawword:function(){
       if (appData.loginMode == 'boss') {
          this.setData({
             seatFeeSet: 0,
             telSet: 0,
             nameSet: 0,
             wifiName:0,
             wifiPassword:1
          })
       } else {
          app.toast('掌柜登录才能操作')
       }
    },
    setWifiName:function(){
       if (appData.loginMode == 'boss') {
          this.setData({
             seatFeeSet: 0,
             telSet: 0,
             nameSet: 0,
             wifiName: 1,
             wifiPassword: 0
          })
       } else {
          app.toast('掌柜登录才能操作')
       }
    },
    submitShop: function (e) {
       var param = e.detail.value
       console.log("【shopInfo】", this.data.shopInfo)
       param.Biz_ID = this.data.shopInfo.Biz_ID
       console.log("【param】", param)
       app.getJsonData('biz/Bmg/saveInfo',param,function(res){
          if(res.code==0){
             console.log("【修改成功】",res)
             _this.transcation(param)
          }else{
             console.log("【修改失败】",res)
          }
       })
      //   var that = this
      //   app.getJsonData('api/admin/my_set.php', param, function (res) {
      //       that.unFocus()
      //       if (param.seat_fee) {
      //           appData.shopInfo.shopInfo.seat_fee = param.seat_fee
      //       }
      //       if (param.name) {
      //           appData.shopInfo.shopInfo.name = param.name
      //       }
      //       if (param.tel) {
      //           appData.shopInfo.shopInfo.tel = param.tel
      //       }
      //       that.setData({ shopInfo: appData.shopInfo.shopInfo })
      //   })
    },
   //  更新数据
    transcation:function(param){
       if (param.Biz_Phone) {
          appData.shopInfo.Biz_Phone = param.Biz_Phone
       }
       if (param.Seat_Fee){
          appData.shopInfo.Seat_Fee = param.Seat_Fee
       }
       if (param.Biz_Name) {
          appData.shopInfo.Biz_Name = param.Biz_Name
       }
       if (param.Wifi_Name) {
          appData.shopInfo.Wifi_Name = param.Wifi_Name
       }
       if (param.Wifi_Pass) {
          appData.shopInfo.Wifi_Pass = param.Wifi_Pass
       }
       console.log("【appData.shopInfo】", appData.shopInfo)
       this.setData({ shopInfo: appData.shopInfo})
    }
})